package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.LeaseTermService;
import com.atguigu.stgy.admin.service.impl.LeaseTermServiceImpl;
import com.atguigu.stgy.model.entity.LeaseTerm;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.result.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 租期(lease_term)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("admin/term")
@Tag(name="租期管理模块")
public class LeaseTermController {
    /**
     * 服务对象
     */
    @Resource

    private LeaseTermService leaseTermService;
    //localhost:8080/admin/term/saveOrUpdate
    @Operation(summary = "新增或更新租期")
    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(@RequestBody LeaseTerm leaseTerm){
        boolean b = leaseTermService.saveOrUpdate(leaseTerm);
        return b?R.ok():R.fail(ResultCodeEnum.FAIL);
    }


    @GetMapping("list")
    @Operation(summary = "查询所有租期列表")

    public R<List<LeaseTerm>> list(){
        return R.ok(leaseTermService.list());
    }


 //   http://localhost:8080/admin/term/deleteById?id=6

    @DeleteMapping("deleteById")
    @Operation(summary = "删除租期列表")
    public R deleteById(@RequestParam("id") Long id ){
        boolean b = leaseTermService.removeById(id);
        return b?R.ok():R.fail(ResultCodeEnum.FAIL);

    }
}
